<script setup lang="ts">
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
import { usePageAuth } from '@/hooks/usePageAuth'
import { useUserStore } from '@/store/user'
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'

usePageAuth()

// 初始化用户store
const userStore = useUserStore()

onLaunch(() => {
  // 检查用户登录状态
  checkUserLoginStatus()
})

onShow(() => {
  // App显示
})

onHide(() => {
  // App隐藏
})

/**
 * 检查用户登录状态
 */
function checkUserLoginStatus() {
  const currentUser = userStore.userInfo
  const currentToken = userStore.token

  if (currentUser && currentToken) {
    // 用户已登录
  }
  else {
    // 用户未登录
  }
}
</script>

<style lang="scss">
/* 全局禁用蓝色高亮效果 */
page {
  -webkit-tap-highlight-color: transparent;
}

/* 禁用所有常用元素的蓝色高亮 */
view,
text,
button,
image,
swiper,
swiper-item,
scroll-view,
input,
textarea,
picker,
navigator,
rich-text,
progress,
slider,
switch,
checkbox,
radio,
form,
label {
  -webkit-tap-highlight-color: transparent;
}

button::after {
  border: none;
}

swiper,
scroll-view {
  flex: 1;
  height: 100%;
  overflow: hidden;
}

image {
  width: 100%;
  height: 100%;
  vertical-align: middle;
}

// 单行省略，优先使用 unocss: text-ellipsis
.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

// 两行省略
.ellipsis-2 {
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

// 三行省略
.ellipsis-3 {
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
</style>
